//app.js
var common = require('./utils/util')
let livePlayer = requirePlugin('live-player-plugin')

App({
  onLaunch: function () {
    // 展示本地存储能力
    // var logs = wx.getStorageSync('logs') || []
    // logs.unshift(Date.now())
    // wx.setStorageSync('logs', logs)

    var token = wx.getStorageSync('token') || null

    if(!token){
      this.globalData.openId = wx.getStorageSync('openId') || null
      if(!this.globalData.openId){
        this.hanldelogin()
      }
    }
    this.globalData.userInfo = wx.getStorageSync('userInfo') || null
  },

  hanldelogin(){
    wx.login({
      success: (res) => {
        if (res) {
          if (res.code) {
            common.http('wechat/login', 'POST', (res) => {
              if(res){
                if(res.authorization){
                  wx.setStorage({
                    key:"token",
                    data: res.authorization
                  })
                  wx.setStorage({
                    key:"phone",
                    data: res.phone
                  })
                }else{
                  wx.setStorageSync('openId', res.openid)
                }
              }
            }, {
              code: res.code,
              type: 'xcx'
            })
          }
        }
      },
    })
  },
  globalData: {
    userInfo: null,
    openId:null,
    // 地址转结算所需id（仅限立即购买）
    good_id:null,

    //首页下拉刷新list
    indexList:[],
    //订单下拉刷新list
    orderList:[],
  }

  // "tabBar": {
  //   "custom": true,
  //   "color": "#000000",
  //   "selectedColor": "#000000",
  //   "backgroundColor": "#000000",
  //   "list": [{
  //     "pagePath": "pages/index/index",
  //     "text": "首页"
  //   }, {
  //     "pagePath": "pages/car/car",
  //     "text": "购物车"
  //   }, {
  //     "pagePath": "pages/myself/myself",
  //     "text": "我的"
  //   }]
  // },
})